{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# SymbolicFactor"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "license_cell",
      "metadata": {
        "tags": [
          "remove-cell"
        ]
      },
      "source": [
        "GTSAM Copyright 2010-2022, Georgia Tech Research Corporation,\nAtlanta, Georgia 30332-0415\nAll Rights Reserved\n\nAuthors: Frank Dellaert, et al. (see THANKS for the full author list)\n\nSee LICENSE for the license information"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "A `SymbolicFactor` represents the connectivity (topology) between variables in a factor graph without any specific numerical function associated with it. It's primarily to *illustrate* symbolic elimination. Internally, GTSAM does analyze the structure of other factor graph types without explicitly converting to a symbolic factor graph.\n",
        "\n",
        "It inherits from `gtsam.Factor` and stores the keys (indices) of the variables it connects."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "<a href=\"https://colab.research.google.com/github/borglab/gtsam/blob/develop/gtsam/symbolic/doc/SymbolicFactor.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "tags": [
          "remove-cell"
        ]
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Note: you may need to restart the kernel to use updated packages.\n"
          ]
        }
      ],
      "source": [
        "%pip install --quiet gtsam-develop"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {},
      "outputs": [],
      "source": [
        "import gtsam\n",
        "from gtsam import SymbolicFactor\n",
        "from gtsam.symbol_shorthand import X\n",
        "\n",
        "# Example Keys\n",
        "x0, x1, x2 = X(0), X(1), X(2)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Creating SymbolicFactors\n",
        "\n",
        "SymbolicFactors can be created by specifying the keys they involve."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Unary Factor f0: \n",
            "  x0\n",
            "Binary Factor f1: \n",
            "  x0 x1\n",
            "Ternary Factor f2: \n",
            "  x1 x2 x0\n",
            "Factor f3 from KeyVector: \n",
            "  x0 x1 x2\n"
          ]
        }
      ],
      "source": [
        "# Unary factor\n",
        "f0 = SymbolicFactor(x0)\n",
        "f0.print(\"Unary Factor f0: \\n\")\n",
        "\n",
        "# Binary factor\n",
        "f1 = SymbolicFactor(x0, x1)\n",
        "f1.print(\"Binary Factor f1: \\n\")\n",
        "\n",
        "# Ternary factor\n",
        "f2 = SymbolicFactor(x1, x2, x0)\n",
        "f2.print(\"Ternary Factor f2: \\n\")\n",
        "\n",
        "# From a list of keys\n",
        "keys = gtsam.KeyVector([x0, x1, x2])\n",
        "f3 = SymbolicFactor.FromKeys(keys)\n",
        "f3.print(\"Factor f3 from KeyVector: \\n\")"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "py312",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}